package com.skygrass.caesar.proxy.filter;

import javax.servlet.http.HttpServletRequest;

import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

@Component
public class PreFiletr extends ZuulFilter
{

	@Override
	public Object run()
	{
		RequestContext ctx = RequestContext.getCurrentContext();
		HttpServletRequest request = ctx.getRequest();
		String parameter = request.getParameter("user");
		if ("zhuyun".equals(parameter))
		{
			System.out.println("-------------------------user ok-------------------------");
		}
		else
		{
			//			System.out.println("-------------------------user error-------------------------");
			//			ctx.setSendZuulResponse(false);
			//			ctx.setResponseStatusCode(401);
			//			ctx.setResponseBody("not access");

			throw new RuntimeException("no access exception");
		}
		return null;
	}

	@Override
	public boolean shouldFilter()
	{
		return true;
	}

	@Override
	public int filterOrder()
	{
		return 0;
	}

	@Override
	public String filterType()
	{
		return FilterConstants.PRE_TYPE;
	}

}
